﻿@namespace MudBlazor.Charts

@inherits MudChartBase<T, IChartOptions>

@typeparam T

@if (ShowLegend is not false)
{
    <div @attributes="UserAttributes" class="mud-chart-legend">
        @foreach (var item in Data)        
        {
            <div class="mud-chart-legend-item" 
                 @onclick:stopPropagation=@(ChartContainer!=null)
                 @onclick=@(async ()=>{ if (OnLegendSelected.HasDelegate) { await OnLegendSelected.InvokeAsync(item.Index); }})>
                @if(CanHideSeries == false)
                {
                    <span class="mud-chart-legend-marker" style="@($"background-color:{ChartPalette!.GetValue(item.Index % ChartPalette.Length)}")"></span>
                    <MudText Typo="Typo.body2" HtmlTag="span">@item.Labels</MudText>
                }
                else
                {   
                    <div class="mud-chart-legend-checkbox" style="@GetCheckBoxStyle(item.Index)">    
                        <MudCheckBox Value="@item.Visible" ValueChanged="@((bool value) => item.HandleCheckboxChangeAsync())" Size="Size.Small" Dense></MudCheckBox>
                        <MudText Typo="Typo.body2" Class="ml-n2 align-self-end" HtmlTag="span">@item.Labels</MudText>
                    </div> 
                }                 
            </div>
        }
    </div>
}
